$(function () {

    var c_url = "iifoxHandler/answer";
    var $table = $('table');

    $table.lgbTable({
        url: c_url,
        if_blank: true,
        PostUrl: "iifox/answerdetail/",
        dataBinder: {
            map: {
                //AE_ID: "#AE_ID"
            },
            callback: function (data) {
                if (data && data.success && data.oper === 'save'
                    && data.data.UserName === $('#userDisplayName').attr('data-userName')) {
                    $('#userDisplayName').text(data.data.DisplayName);
                }
                if (data && data.oper === 'create') {
                    $('#userName').prop('readonly', false).removeClass("ignore");
                }
                else if (data && data.oper === 'edit') {
                    $('#userName').prop('readonly', true).addClass("ignore");
                }
            }
        },
        smartTable: {
            idField: "AE_ID",
            sortName: "AE_ID",
            sortOrder: "asc",
            queryParams: function (params) {
                return $.extend(params, {
                    IP: $("#txt_IP").val(),
                    Phone: $('#txt_Phone').val()
                });
            },           //传递参数（*）
            columns: [
                { title: "AE_ID", field: "AE_ID", sortable: true },
                { title: "IP", field: "IP", sortable: true },
                { title: "M_ID", field: "M_ID", sortable: true },
                { title: "A_ID", field: "A_ID", sortable: true },
                { title: "IsFinished", field: "IsFinished", sortable: true },
                { title: "AnswerDate", field: "AnswerDate", sortable: true },
                { title: "Email", field: "Email", sortable: true },
                { title: "Phone", field: "Phone", sortable: true },
                { title: "vFlag", field: "vFlag", sortable: true },
                { title: "vUser", field: "vUser", sortable: true },
                { title: "SurvryCode", field: "SurvryCode", sortable: true },
                { title: "nFile", field: "nFile", sortable: true },
                { title: "vFlag2", field: "vFlag2", sortable: true },
                { title: "CusName", field: "CusName", sortable: true }
            ],
            editButtons: {
                events: {
                    'click': function (e, value, row, index) {
                        $table.bootstrapTable('uncheckAll');
                        $table.bootstrapTable('check', index);
                    }
                },
                formatter: function (value, row, index) {
                    var $this = this.clone();
                    if (row.IsReset === 0) {
                        $this.find('button.reset').remove();
                    }
                    return $this.html();
                }
            },
            exportOptions: {
                fileName: "用户数据",
                ignoreColumn: [0, 7]
            }
        }
    });
});